import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.util.concurrent.Flow;

public class Context {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        // 1 获取配置信息以及获取 job 对象
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        // 2 关联本 Driver 程序的 jar
        job.setJarByClass(Context.class);

        // 3 关联 Mapper 和 Reducer 的 jar
        job.setMapperClass(FlowMapper.class);
        job.setReducerClass(FlowReduce.class);


        // 4 设置 Mapper 输出的 kv 类型
        job.setMapOutputKeyClass(FlowBean.class);
        job.setMapOutputValueClass(Text.class);

        // 5 设置最终输出 kv 类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);
        
        // 自定义分区
        job.setPartitionerClass(ProvincePartition2.class);
        job.setNumReduceTasks(4);

        FileInputFormat.setInputPaths(job, new Path("E:\\学习资料\\java\\尚硅谷hadoop笔记\\笔记\\笔记\\phone.txt"));
        FileOutputFormat.setOutputPath(job, new Path("E:\\学习资料\\java\\尚硅谷hadoop笔记\\笔记\\笔记\\re.txt"));

        // 7 提交 job
        boolean result = job.waitForCompletion(true);
        // 6 设置输入和输出路径

        System.exit(result ? 0 : 1);
    }
}
